yjx.controller('productSearchController', ['$scope', '$timeout', '$fetch', '$stateParams', 'modalService','$init', function ($scope, $timeout, $fetch, $stateParams, modalService,$init) {
    var api = '/product/dimensions/',
        params = {};
    $scope.curTagId = $stateParams.classId?$stateParams.classId:0;
    $init.title("产品分类")
    function getTags() {
        if ($scope.keyword) {
            params.keyword = $scope.keyword;
        }
        $fetch.fetch(
            api,
            {
                params: params
            }
        ).then(function (data) {
            $timeout(function () {
                if(data){
                    $scope.dataList = data.dimension;
                    $scope.curTab = $scope.dataList[0];
                    buildMainSwiper();
                }
                
            })
        }).catch(function (e) {
            modalService.mainErrorMsg(e.msg);
        })
    }
    /**搜索用 */
    $scope.keyword = '';
    $scope.search = function () {
        getTags();
    },
        $scope.searchKey = function ($event) {
            if ($event.keyCode == 13) {
                getTags();
            }
        }
        getTags();
    /**测试用 */
    // $scope.dataList = [
    //     {
    //         id: 1,
    //         tags: [{ id: 1, name: '男性', tags: [{ id: 1, name: '男性肿瘤' }, { id: 2, name: '男性用药' }, { id: 3, name: '男性心脑血管' }] }, { id: 2, name: '女性', tags: [{ id: 5, name: 'hpv' }, { id: 6, name: '女性生育能力检测' }] }],
    //         name: '适用人群'
    //     },
    //     {
    //         id: 2,
    //         tags: [{ id: 1, name: '男性', tags: [{ id: 1, name: '男性肿瘤' }, { id: 2, name: '男性用药' }, { id: 3, name: '男性心脑血管' }] }, { id: 2, name: '女性', tags: [{ id: 5, name: 'hpv' }, { id: 6, name: '女性生育能力检测' }] }],
    //         name: '适用阶段'
    //     },
    //     {
    //         id: 3,
    //         tags: [{ id: 1, name: '男性', tags: [{ id: 1, name: '男性肿瘤' }, { id: 2, name: '男性用药' }, { id: 3, name: '男性心脑血管' }] }, { id: 2, name: '女性', tags: [{ id: 5, name: 'hpv' }, { id: 6, name: '女性生育能力检测' }] }],
    //         name: '适用行业'
    //     },
    //     {
    //         id: 4,
    //         tags: [{ id: 1, name: '男性', tags: [{ id: 1, name: '男性肿瘤' }, { id: 2, name: '男性用药' }, { id: 3, name: '男性心脑血管' }] }, { id: 2, name: '女性', tags: [{ id: 5, name: 'hpv' }, { id: 6, name: '女性生育能力检测' }] }],
    //         name: '适用疾病'
    //     },
    // ]
   
    var tabSwiper;
    var curSwiper;
    var width = document.body.offsetWidth;
    function buildMainSwiper() {
        $timeout(function () {
            tabSwiper = new Swiper('#tabList3', {
                slidesPerView: 4,
                slideToClickedSlide: true,
                sliderOffsetBefore: 10,
                sliderOffsetAfter: 10,
            })
            curSwiper = new Swiper('#proCatSwiper', {
                slider: width,
                on: {
                    slideNextTransitionStart: function () {
                        tabSwiper.slideTo(curSwiper.activeIndex, 500);
                        $timeout(function () {
                            $scope.curTab = $scope.dataList[curSwiper.activeIndex];
                        })
                    },
                    slidePrevTransitionStart: function () {
                        tabSwiper.slideTo(curSwiper.activeIndex - 1);
                        $timeout(function () {
                            $scope.curTab = $scope.dataList[curSwiper.activeIndex];
                        })
                    }
                }
            })
        })
    }
    $scope.tabSelect = function (item, index) {
        $scope.curTab = item;
        curSwiper.slideTo(index, 500);
    }
   
}])